using System;
using System.Text.RegularExpressions;

namespace libntregsharp
{
	public class HBinBlock : IKey
	{
		private Regex _regex;
		
		public HBinBlock() {}
		
		public HBinBlock (int index, byte[] hive)
		{
			
			//the lengths we will be working with.
			int word = 2; //word 2 your mother
			int dword = word+word; //double word
			int qword = dword+dword; //quad word
			
			byte[] tmp = new byte[dword];
			for (int i = 0; i < dword; i++)
				tmp[i] = hive[index+i+(int)0x0004];
			
			OffsetFromFirstHbin = BitConverter.ToInt32(tmp, 0);
			
			for (int i = 0; i < dword; i++)
				tmp[i] = hive[index+i+(int)0x008];
			
			OffsetToNextHbin = BitConverter.ToInt32(tmp, 0);
			
			for (int i = 0; i < dword; i++)
				tmp[i] = hive[index+i+(int)0x001C];
			
			Blocksize = BitConverter.ToInt32(tmp, 0);
		}
		
		public int OffsetFromFirstHbin { get; private set; }
		
		public int OffsetToNextHbin { get; private set; }
		
		public int Blocksize { get; private set; }
		
		public Regex Regex
		{
			get 
			{
				if (_regex == null)
					_regex = new Regex (@"hbin.{4}\x00\x10\x00\x00");
				
				return _regex;
			}
		}
	}
}

